import React, { Suspense } from "react";
import { Switch, Redirect, Route } from "react-router-dom";

const Routerview = (props) => (
    <Suspense fallback={<div>Loading...</div>}>
        <Switch>
            {props.routes.map((item, index) => {
                if (item.to) return <Redirect key={index} from={item.from} to={item.to} />;
                return <Route key={index} path={item.path} component={item.component} />;
            })}
        </Switch>
    </Suspense>
);

export default Routerview;
